#!/usr/bin/perl
# 
# Exercise 10.4
# 
# Design a module of subroutines to handle the following kinds of data: a flat file 
# containing records consisting of gene names on a line and extra information of any 
# sort on succeeding lines, followed by a blank line. Your subroutines should be able 
# to read in the data and then do a fast lookup on the information associated with a 
# gene name. You should also be able to add new records to the flat file. Now reuse 
# this module to build an address book program.
#
# Program that uses the module for exercise 10.4

# This program implements a database using the subroutines defined
# in the module.  It supports querying and adding to the database.

use strict;
use warnings;
use exer1004; # This will use the module file exer1004.pm

# The ASCII flat file that holds the database
my $databasefile = 'exer10.04.data';

# Read in the database from the flat file to a hash
my %genedata = readdatabase($databasefile);

# Test by examining a key-value pair
print "See what entry?: ";
my $ans = <STDIN>;
chomp $ans;
print $genedata{$ans};

# Get a new record for the database from the user
my @newrecord = getnewrecord;

# Add a new record to the database
addrecord($databasefile, @newrecord);

# Reload the database from the database file
%genedata = readdatabase($databasefile);

# Test by examining a key-value pair
print "See what entry?: ";
$ans = <STDIN>;
chomp $ans;
print $genedata{$ans};

exit;


# To accomplish the final challenge, you can see that this program will
# work exactly as is to support an address book database.  Just use a different
# database file that contains the address book information.
